package managerview;

import customerview.BuyBook;
import customerview.UsersView;
import users.ManagerFun;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class AddBook extends JFrame {
    public AddBook(){
        //初始化界面
        initJFrame();
        //在这个界面添加内容
        initView();
        //让页面展示出来
        this.setVisible(true);

    }

    private void initView() {

        //添加返回主界面按钮
        JButton ReturnButton=new JButton();
        ReturnButton.setBounds(30,10,110,30);
        ReturnButton.setText("返回主界面");
        this.getContentPane().add(ReturnButton);
        //添加监听
        ReturnButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                AddBook.this.setVisible(false);
                new MangeView();
            }
        });


        //添加...文字
        JLabel Text1=new JLabel("name：");
        Text1.setBounds(180,50,50,50);
        this.getContentPane().add(Text1);
        //添加...输入框
        JTextField searchText1 = new JTextField(10);
        searchText1.setBounds(250,60,150,30);
        this.getContentPane().add(searchText1);

        //添加...文字
        JLabel Text2=new JLabel("type：");
        Text2.setBounds(180,120,50,50);
        this.getContentPane().add(Text2);
        //添加...输入框
        JTextField searchText2 = new JTextField(10);
        searchText2.setBounds(250,130,150,30);
        this.getContentPane().add(searchText2);

        //添加...文字
        JLabel Text3=new JLabel("publish：");
        Text3.setBounds(180,190,50,50);
        this.getContentPane().add(Text3);
        //添加...输入框
        JTextField searchText3 = new JTextField(10);
        searchText3.setBounds(250,200,150,30);
        this.getContentPane().add(searchText3);

        //添加...文字
        JLabel Text4=new JLabel("price：");
        Text4.setBounds(180,260,50,50);
        this.getContentPane().add(Text4);
        //添加...输入框
        JTextField searchText4 = new JTextField(10);
        searchText4.setBounds(250,270,150,30);
        this.getContentPane().add(searchText4);

        //添加添加图书按钮
        JButton addButton=new JButton();
        addButton.setBounds(240,330,100,30);
        addButton.setText("添加图书");
        this.getContentPane().add(addButton);
        //添加监听
        //.....
        addButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    ManagerFun.addbook(searchText1.getText(),searchText2.getText(),searchText3.getText(),searchText4.getText());
                } catch (Exception ex) {
                    throw new RuntimeException(ex);
                }
            }
        });


    }

    private void initJFrame() {
        this.setTitle("添加新图书");
        this.setSize(590, 430);
        //设置页面居中
        this.setLocationRelativeTo(null);
        //设置关闭模式
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //取消按钮等元素居中放置
        this.setLayout(null);
    }
}
